home *** CD-ROM | disk | FTP | other *** search
/ Delphi Magazine Collection 2001 / Delphi Magazine Collection 20001 (2001).iso / DISKS / ISSUE23 / PASTOWEB / PasToWebForm.pas < prev    next >
Pascal/Delphi Source File  |  1997-05-09  |  3KB  |  122 lines

  1. unit PasToWebForm;
  2.  
  3. interface
  4.  
  5. uses
  6.   Windows, Messages, SysUtils, Classes, Graphics, Controls,
  7.   Forms, Dialogs, StdCtrls;
  8.  
  9. type
  10.   TForm1 = class (TForm)
  11.     EditSource: TEdit;
  12.     BtnHTML: TButton;
  13.     EditCopyr: TEdit;
  14.     BtnInput: TButton;
  15.     OpenDialog1: TOpenDialog;
  16.     EditDest: TEdit;
  17.     Label1: TLabel;
  18.     Label2: TLabel;
  19.     Label3: TLabel;
  20.     BtnOpen: TButton;
  21.     BtnInfo: TButton;
  22.     procedure BtnHTMLClick(Sender: TObject);
  23.     procedure BtnInputClick(Sender: TObject);
  24.     procedure EditDestChange(Sender: TObject);
  25.     procedure BtnOpenClick(Sender: TObject);
  26.     procedure BtnInfoClick(Sender: TObject);
  27.   end;
  28.  
  29. var
  30.   Form1: TForm1;
  31.  
  32. implementation
  33.  
  34. {$R *.DFM}
  35.  
  36. uses
  37.   Convert, ShellApi;
  38.  
  39. procedure TForm1.BtnHTMLClick(Sender: TObject);
  40. var
  41.   Source, BinSource, Dest: TStream;
  42.   Parser: THtmlParser;
  43. begin
  44.   // extract the target file name
  45.   if FileExists (EditDest.Text) then
  46.     if MessageDlg ('Overwrite the existing file ' + EditDest.Text + '?',
  47.       mtConfirmation, [mbYes, mbNo], 0) = idNo then
  48.     Exit;
  49.   // create the two streams
  50.   Dest := TFileStream.Create (EditDest.Text,
  51.     fmCreate or fmOpenWrite);
  52.   if ExtractFileExt(EditSource.Text) = '.dfm' then
  53.   begin
  54.     // convert the DFM file to text
  55.     BinSource := TFileStream.Create (EditSource.Text, fmOpenRead);
  56.     Source := TMemoryStream.Create;
  57.     ObjectResourceToText (BinSource, Source);
  58.     Source.Position := 0;
  59.   end
  60.   else
  61.   begin
  62.     Source := TFileStream.Create (EditSource.Text, fmOpenRead);
  63.     BinSource := nil;
  64.   end;
  65.   // parse the source code
  66.   try
  67.     Parser := THtmlParser.Create (Source, Dest);
  68.     try
  69.       Parser.Alone := True;
  70.       Parser.Filename := EditSource.Text;
  71.       Parser.Copyright := EditCopyr.Text;
  72.       if ExtractFileExt(EditSource.Text) = '.dfm' then
  73.         Parser.SetKeywordType (ktDfm);
  74.       Parser.Convert;
  75.     finally
  76.       Parser.Free;
  77.     end;
  78.   finally
  79.     Dest.Free;
  80.     Source.Free;
  81.     BinSource.Free;
  82.   end;
  83.   // enable the third button
  84.   BtnOpen.Enabled := True;
  85. end;
  86.  
  87. procedure TForm1.BtnInputClick(Sender: TObject);
  88. begin
  89.   with OpenDialog1 do
  90.     if Execute then
  91.     begin
  92.       EditSource.Text := Filename;
  93.       EditDest.Text := ChangeFileExt(FileName, '_' +
  94.         Copy (ExtractFileExt(Filename), 2, 3)) + '.HTM';
  95.       BtnHtml.Enabled := True;
  96.     end;
  97. end;
  98.  
  99. procedure TForm1.EditDestChange(Sender: TObject);
  100. begin
  101.   BtnOpen.Enabled := False;
  102. end;
  103.  
  104. procedure TForm1.BtnOpenClick(Sender: TObject);
  105. begin
  106.   ShellExecute (Handle, 'open',
  107.      PChar (EditDest.Text), '', '', sw_ShowNormal);
  108. end;
  109.  
  110. procedure TForm1.BtnInfoClick(Sender: TObject);
  111. begin
  112.   // this isn't true any more
  113.   MessageDlg (Caption + #13#13 +
  114.     'Web: http://ourworld.compuserve.com/homepages/marcocantu'#13 +
  115.     'Email: marcocantu@compuserve.com',
  116.     mtInformation, [mbOK], 0);
  117. end;
  118.  
  119. end.
  120.  
  121.  
  122.